%Take all of the final steps to prep for group level analysis:
function group_level_prep_univ(sub)



if sub < 10
    s = ['0',num2str(sub)]
else s = num2str(sub)
end

    cd(sprintf('/ncf/cushman/Regan/desert_island/desisl_%s/desisl_%s.results', s, s))
  
%%    
%1. Deoblique EPI and dataset
    
    %pull out glt from stats bucket    
    unix(sprintf(['3dTcat -prefix desisl_',s,'_hadvdid_univ BLOCK_81_hadvdid_blur6.stats.desisl_',s,'+orig[7]']));

    %deoblique glt
    unix(sprintf(['3dWarp -deoblique -prefix deoblw_desisl_',s,'_hadvdid_univ desisl_',s,'_hadvdid_univ+orig']));

    cd ../
 
    %deoblique EPI
    if ~exist(['deoblw_desisl_',s,'.run2+orig.HEAD'])
    unix(sprintf(['3dWarp -deoblique -prefix deoblw_desisl_',s,'.run2 desisl_',s,'.run2+orig']));
    end


%%

%2. If warping has been done before, move all of the relevant files from the
%ANTS files folder out and into the subject's folder for use again.
if exist('ANTS_files')
    unix(sprintf('cp ANTS_files/* .'));
end

cd ~/../../ncf/cushman/Regan/desert_island


%% 
%3. Align the stats datasets to the template
    unix(sprintf(['python stats_to_template.py desisl_',s,' desisl_',s,'/desisl_',s,'.results/deoblw_desisl_',s,'_hadvdid_univ+orig']));  
  
%%

%4. Clean up old files and move all of the relevant files into a single directory
    
    cd(['~/../../ncf/cushman/Regan/desert_island/desisl_',s,'/desisl_',s,'.results']);
        
    unix(sprintf(['cp *deoblw*hadvdid*template* ../../groupdata/univariate/individual_subj_data']));

    cd ../
    %clean up each subject's directory by moving all of the ANTS files into a
    %new folder
    if ~isfile('ANTS_files')
        mkdir ANTS_files 
    end
    
    
    movefile *Brain* ANTS_files
    movefile *skull* ANTS_files
    movefile *verse* ANTS_files
    movefile *anat_to_* ANTS_files
    movefile *1Warp* ANTS_files
    movefile *Gen* ANTS_files
    movefile *anat_deob* ANTS_files
    movefile *_vr_* ANTS_files

%%
cd('~/../../ncf/cushman/Regan/desert_island/groupdata/univariate/individual_subj_data');

%5. Resample data to a 2x2x2 grid to work with 3dttest++ -Clustsim
  
    %Average Accuracy
    unix(sprintf(['3dresample -dxyz 2.0 2.0 2.0 -prefix desisl_',s,'_hadvdid_univ -input deoblw_desisl_',s,'_hadvdid_univ_template.nii']));



end




